package com.eigaland.change_machine.customview

import android.content.Context
import android.graphics.Color
import android.widget.FrameLayout
import com.eigland.eigaland_lib.model.SeatPlan
import movie6.posprintercept2.extensions.dip
import movie6.posprintercept2.extensions.removeParentView
import movie6.posprintercept2.extensions.setBackgroundColorWithDefault

class SeatPlanView(context: Context, val seatPlan: SeatPlan) : FrameLayout(context) {

    val sectionViews by lazy {
        seatPlan.sections.map { section ->
            val view = SectionView(context,null ,section)
            view.x = dip(section.x).toFloat()
            view.y = dip(section.y).toFloat()

            view.pivotX = (section.w / 2).toFloat()
            view.pivotY = (section.h / 2).toFloat()
            view.rotation = section.r

            view
        }
    }

    init {

        layoutParams = LayoutParams(
            dip(seatPlan.w.toFloat()),
            dip(seatPlan.h.toFloat())
        )

//        setBackgroundColorWithDefault(seatPlan.bgColor, Color.GREEN)


        sectionViews.forEach {
            addView(it.removeParentView())
        }
    }
}